<?php

/**
 * This is the model class for table "user".
 *
 * The followings are the available columns in table 'user':
 * @property integer $id
 * @property string $email
 * @property string $pass
 * @property string $lastest_login
 * @property string $last_name
 * @property string $first_name
 * @property integer $login_attempts
 * @property integer $active
 * @property integer $group_id
 * @property integer $sex
 * @property string $birthday
 * @property string $address
 * @property string $active_code
 * @property string $created_date
 * @property string $modified_date
 * @property string $mobile
 * @property string $note
 */
class User extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return User the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'user';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('email, pass, last_name, first_name, created_date', 'required'),
			array('login_attempts, active, group_id, sex', 'numerical', 'integerOnly'=>true),
			array('email, pass, last_name, first_name, address', 'length', 'max'=>255),
			array('active_code, mobile', 'length', 'max'=>50),
			array('lastest_login, birthday, modified_date, note', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, email, pass, lastest_login, last_name, first_name, login_attempts, active, group_id, sex, birthday, address, active_code, created_date, modified_date, mobile, note', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'email' => 'Email',
			'pass' => 'Pass',
			'lastest_login' => 'Lastest Login',
			'last_name' => 'Last Name',
			'first_name' => 'First Name',
			'login_attempts' => 'Login Attempts',
			'active' => 'Active',
			'group_id' => 'Group',
			'sex' => 'Sex',
			'birthday' => 'Birthday',
			'address' => 'Address',
			'active_code' => 'Active Code',
			'created_date' => 'Created Date',
			'modified_date' => 'Modified Date',
			'mobile' => 'Mobile',
			'note' => 'Note',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('email',$this->email,true);
		$criteria->compare('pass',$this->pass,true);
		$criteria->compare('lastest_login',$this->lastest_login,true);
		$criteria->compare('last_name',$this->last_name,true);
		$criteria->compare('first_name',$this->first_name,true);
		$criteria->compare('login_attempts',$this->login_attempts);
		$criteria->compare('active',$this->active);
		$criteria->compare('group_id',$this->group_id);
		$criteria->compare('sex',$this->sex);
		$criteria->compare('birthday',$this->birthday,true);
		$criteria->compare('address',$this->address,true);
		$criteria->compare('active_code',$this->active_code,true);
		$criteria->compare('created_date',$this->created_date,true);
		$criteria->compare('modified_date',$this->modified_date,true);
		$criteria->compare('mobile',$this->mobile,true);
		$criteria->compare('note',$this->note,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}